package cn.com.eado.uwallpaper;

import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;

import com.alibaba.fastjson.JSON;
import com.squareup.okhttp.Callback;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.Response;

import java.io.IOException;
import java.util.List;

import butterknife.InjectView;
import cn.com.eado.uwallpaper.bean.MeiziBean;
import cn.com.eado.uwallpaper.net.OkhttpRequest;
import cn.com.eado.uwallpaper.utils.TUtil;

public class ItemActivity extends AppCompatActivity {

    private String url;
    private MeiziBean meiziBean;
    @InjectView(R.id.rv_meizi)
    RecyclerView rv_meizi;
    private List<MeiziBean.ResEntity.WallpaperEntity> wallpaperEntityList;

    private Handler mHandler=new Handler(){
        @Override
        public void handleMessage(Message msg) {
            rv_meizi.setAdapter(new MeiziAdapter(ItemActivity.this, wallpaperEntityList));
        }
    };
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_item);
        url = getIntent().getStringExtra("url");//这个分类下的全部壁纸；
        TUtil.showL(url);
        if (url != null && !"".equals(url)) {
            OkhttpRequest.getInstance().getRequest("http://service.picasso.adesk.com/v1/wallpaper/category/4e4d610cdf714d2966000000/wallpaper", new Callback() {
                @Override
                public void onFailure(Request request, IOException e) {

                }

                @Override
                public void onResponse(Response response) throws IOException {
                    String json=response.body().string();
                    TUtil.showL("返回json=="+json);
                    meiziBean= JSON.parseObject(response.body().string(), MeiziBean.class);
//                    Gson gson = GsonUtil.getInstance().getGson();
//                    Gson gson=new Gson();
//                    meiziBean = gson.fromJson(json, MeiziBean2.class);
                    meiziBean.toString();
                    wallpaperEntityList = meiziBean.getRes().getWallpaper();
                    mHandler.sendEmptyMessage(1);
                }
            });
        }
    }
}
